﻿package plugin.instances.game
{
    import com.core.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.filters.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.instance.*;
    import plugin.instances.*;
    import plugin.ybstore.consts.*;
    import pluginfw.nio.*;
    import uiresource.instances.ui.*;
    import view.effect.*;
    import view.message.*;
    import view.mornExtends.*;

    public class FbviewGame extends FbviewUI implements IInstance
    {
        private var _instance:Object;
        private var reward:Array;
        public var alert:Alert2;
        private var tween:TweenMax;
        private var doubleTips:String = "";
        private var _showDouble:Boolean = true;
        private var _timeID:uint = 0;

        public function FbviewGame()
        {
            return;
        }// end function

        public function initShow(param1:Object, param2:Dictionary) : void
        {
            var _loc_3:Array = null;
            var _loc_4:Object = null;
            this._instance = param1;
            switch(int(this.reward[2]))
            {
                case 2:
                {
                    break;
                }
                case 3:
                {
                    break;
                }
                case 4:
                {
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            this.showItem(param1.show);
            if (param2[InstancesPublic.MONSTERNUM])
            {
                this.updateShow(InstancesPublic.MONSTERNUM, param2[InstancesPublic.MONSTERNUM]);
            }
            btn_quit.filters = [];
            btn_lingqu.clickHandler = new Handler(this.doLq, [1]);
            return;
        }// end function

        private function doLq(param1:int) : void
        {
            var rate:* = param1;
            if (this.reward)
            {
                if (this.reward[2] == rate)
                {
                    switch(int(this.reward[0]))
                    {
                        case 2:
                        {
                            break;
                        }
                        case 3:
                        {
                            break;
                        }
                        default:
                        {
                            break;
                            break;
                        }
                    }
                    return;
                }
            }
            this.sendlqMsg(rate);
            return;
        }// end function

        public function sendlqMsg(param1:int) : void
        {
            var _loc_2:* = new Output();
            _loc_2.writeVarInt(this._instance.mapid, false);
            _loc_2.writeVarInt(param1, false);
            PluginManager.instance.sendToBufferServer("instance", CMDInstance.GetRewards, _loc_2);
            return;
        }// end function

        private function getMoney(param1:int) : Number
        {
            var _loc_2:* = UserData.getBagData();
            var _loc_3:Number = 0;
            switch(param1)
            {
                case 1:
                {
                    _loc_3 = _loc_2.bgold;
                    break;
                }
                case 3:
                {
                    _loc_3 = _loc_2.money;
                    break;
                }
                case 2:
                {
                    _loc_3 = _loc_2.bonus;
                    break;
                }
                case 5:
                {
                    _loc_3 = _loc_2.contribution;
                    break;
                }
                case 6:
                {
                    _loc_3 = _loc_2.gold;
                    break;
                }
                case 9:
                {
                    _loc_3 = _loc_2.zuoqi;
                    break;
                }
                case 10:
                {
                    _loc_3 = _loc_2.yuyi;
                    break;
                }
                case 11:
                {
                    _loc_3 = _loc_2.shengwang;
                    break;
                }
                case 15:
                {
                    _loc_3 = _loc_2.jifen;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return _loc_3;
        }// end function

        protected function doBuy(event:MouseEvent) : void
        {
            var _loc_2:* = event.currentTarget.dataSource;
            PluginManager.instance.sendToServer("store", CMDStore.GetPrice, _loc_2.storeId);
            return;
        }// end function

        public function updateShow(param1:int, param2:Object) : void
        {
            var _loc_3:BezierStar = null;
            switch(param1)
            {
                case InstancesPublic.TIMECHECKER:
                {
                    txt_time.text = "倒计时：" + TimeDataFormatUtil.getLeftTime(int(param2));
                    break;
                }
                case InstancesPublic.CLEARANCE:
                {
                    ModelProxy.change("mainui", "showClearance", null);
                    btn_quit.visible = false;
                    btn_lingqu.visible = true;
                    if (this._showDouble)
                    {
                        btn_doublelingqu.visible = true;
                        this.tween = TweenMax.to(btn_doublelingqu, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    }
                    else
                    {
                        btn_lingqu.x = btn_quit.x;
                        this.tween = TweenMax.to(btn_lingqu, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
                    }
                    img_clear.visible = false;
                    img_clear.scale = 2.5;
                    img_clear.x = 20;
                    img_clear.y = 40;
                    img_clear.filters = [new ColorMatrixFilter([1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1])];
                    _loc_3 = new BezierStar();
                    this.addChild(_loc_3);
                    _loc_3.allMoveline(-500, 65, 0, 65);
                    this._timeID = setTimeout(this.showAnimate, 800);
                    break;
                }
                case InstancesPublic.ISGET:
                {
                    this.doQuit();
                    break;
                }
                case InstancesPublic.MONSTERNUM:
                {
                    if (param2.bossnumber == 0)
                    {
                        txt_msg.text = "击杀小怪:<font color=\'#" + (param2.allNumber == param2.killnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.killnumber + "/" + param2.allNumber + ")</font>";
                        if (param2.killnumber == param2.allNumber)
                        {
                            this.updateShow(InstancesPublic.CLEARANCE, null);
                        }
                    }
                    else if (param2.allNumber == 0)
                    {
                        txt_msg.text = "击杀" + this._instance.boss + ":<font color=\'#" + (param2.bknumber == param2.bossnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.bknumber + "/" + param2.bossnumber + ")</font>";
                        if (param2.bknumber == param2.bossnumber)
                        {
                            this.updateShow(InstancesPublic.CLEARANCE, null);
                        }
                    }
                    else
                    {
                        txt_msg.text = "击杀" + this._instance.boss + ":<font color=\'#" + (param2.bknumber == param2.bossnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.bknumber + "/" + param2.bossnumber + ")</font><br>击杀小怪:<font color=\'#" + (param2.allNumber == param2.killnumber ? ("52b335") : ("c62440")) + "\'>(" + param2.killnumber + "/" + param2.allNumber + ")</font>";
                        if (param2.bknumber == param2.bossnumber && param2.killnumber == param2.allNumber)
                        {
                            this.updateShow(InstancesPublic.CLEARANCE, null);
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function doShowEffect() : void
        {
            if (this._showDouble)
            {
                this.tween = TweenMax.to(btn_doublelingqu, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
            }
            else
            {
                this.tween = TweenMax.to(btn_lingqu, 1, {glowFilter:{color:16763904, alpha:1, blurX:10, blurY:10}, yoyo:true, repeat:int.MAX_VALUE, alpha:1});
            }
            return;
        }// end function

        private function showAnimate() : void
        {
            if (this._timeID > 0)
            {
                clearTimeout(this._timeID);
                this._timeID = 0;
            }
            img_clear.visible = true;
            TweenMax.to(img_clear, 0.5, {x:72, y:82, alpha:1, scale:1, ease:Back.easeIn, onComplete:this.doCom, colorMatrixFilter:[11, 0, 0, 0, 465, 0, 11, 0, 0, 465, 0, 0, 11, 0, 465, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1], blurFilter:{blurX:5, blurY:5}});
            return;
        }// end function

        public function doCom() : void
        {
            img_clear.filters = null;
            return;
        }// end function

        private function showItem(param1:String) : void
        {
            var _loc_2:* = new ItemSplit();
            var _loc_3:* = _loc_2.doSplits(param1, "&", "/", "#");
            list_goods.array = _loc_3[0];
            list_goods.renderHandler = new Handler(this.itemRender);
            return;
        }// end function

        private function itemRender(param1:Component, param2:int) : void
        {
            var _loc_3:Object = null;
            var _loc_4:FlashItem = null;
            var _loc_5:Label = null;
            if (param2 < list_goods.length)
            {
                _loc_3 = list_goods.array[param2];
                _loc_4 = param1.getChildByName("fi") as FlashItem;
                _loc_4.data = _loc_3;
                _loc_5 = param1.getChildByName("txt_name") as Label;
                _loc_5.text = _loc_3.name + "X" + _loc_3.count;
            }
            return;
        }// end function

        public function destroyShow(param1:Dictionary) : void
        {
            if (this.alert)
            {
                this.alert.clickHandler3();
                this.alert = null;
            }
            if (this.tween)
            {
                this.tween.kill();
                this.tween = null;
            }
            return;
        }// end function

        public function initEvent() : void
        {
            btn_quit.clickHandler = new Handler(this.doQuit);
            btn_doublelingqu.addEventListener(MouseEvent.ROLL_OVER, this.doDoubleLqOver);
            btn_doublelingqu.addEventListener(MouseEvent.ROLL_OUT, this.doOut);
            btn_lingqu.addEventListener(MouseEvent.ROLL_OVER, this.doLqOver);
            btn_lingqu.addEventListener(MouseEvent.ROLL_OUT, this.doOut);
            return;
        }// end function

        protected function doLqOver(event:MouseEvent) : void
        {
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_2:* = UserData.getUserData("vip");
            var _loc_3:* = UserData.getUserData();
            if (_loc_2 <= 0)
            {
                ModelProxy.change("tips", "normal", {data:"拥有特权可免费领取更多奖励"});
            }
            else
            {
                _loc_4 = ConfigDictionary.data.tequan;
                _loc_5 = _loc_4[_loc_2];
                if (_loc_5)
                {
                    ModelProxy.change("tips", "normal", {data:"当前特权可领取" + (_loc_5.instanceexp / 100 + 1) + "倍经验奖励"});
                }
            }
            return;
        }// end function

        protected function doDoubleLqOver(event:MouseEvent) : void
        {
            var _loc_3:Object = null;
            var _loc_4:Object = null;
            var _loc_2:* = UserData.getUserData("vip");
            if (_loc_2 <= 0)
            {
                ModelProxy.change("tips", "normal", {data:this.doubleTips + "\n拥有特权可免费领取更多奖励"});
            }
            else
            {
                _loc_3 = ConfigDictionary.data.tequan;
                _loc_4 = _loc_3[_loc_2];
                if (_loc_4)
                {
                    ModelProxy.change("tips", "normal", {data:this.doubleTips + "\n当前特权可领取" + (_loc_4.instanceexp / 100 + 1) + "倍经验奖励"});
                }
            }
            return;
        }// end function

        protected function doOut(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        private function doQuit() : void
        {
            ModelProxy.change("zone", "exitInstance", null);
            return;
        }// end function

        public function removeEvent() : void
        {
            btn_doublelingqu.removeEventListener(MouseEvent.ROLL_OVER, this.doDoubleLqOver);
            btn_doublelingqu.removeEventListener(MouseEvent.ROLL_OUT, this.doOut);
            btn_lingqu.removeEventListener(MouseEvent.ROLL_OVER, this.doLqOver);
            btn_lingqu.removeEventListener(MouseEvent.ROLL_OUT, this.doOut);
            return;
        }// end function

    }
}
